<style lang="scss" scoped>
  @import '../../styles/common/loading.less';
  .container{
    border: none !important;
    margin-top: 4px;
  }
  .el-col-offset-1 {
    margin-left: 0%;
  }
  .button_a {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);

  }
  .col_a {
    margin-left: 2%;
  }
  .el-card {
    height: 200px;
  }

  .el-button--primary {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);
  }
</style>
<template>
    <div>
        <div class="container">
            <div>
              <el-form :model="prpLDrugCata" ref="prpLDrugCata" class="select-submit-form">
                  <el-row type="flex">
                      <el-col :span="8">
                          <el-form-item prop="drugsCode" label="药品编码">
                              <el-input  v-model="prpLDrugCata.drugsCode"></el-input>
                          </el-form-item>
                      </el-col>
                      <el-col :span="8">
                          <el-form-item prop="drugsName" label="中文名称">
                              <el-input  v-model="prpLDrugCata.drugsName"></el-input>
                          </el-form-item>
                      </el-col>
                    <el-col :span="8">
                      <el-form-item prop="drugsEName" label="英文名称">
                        <el-input  v-model="prpLDrugCata.drugsEName"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex">
                    <el-col :span="8">
                      <el-form-item prop="pinyinCode" label="拼音助记码">
                        <el-input  v-model="prpLDrugCata.pinyinCode"></el-input>
                      </el-form-item>
                    </el-col>

                      <el-col :span="8">
                          <el-form-item prop="drugsFactoryName" label="药厂名称">
                              <el-input  placeholder="请输入" v-model="prpLDrugCata.drugsFactoryName"></el-input>
                          </el-form-item>
                      </el-col>
                    <el-col :span="8">
                      <el-form-item label="有效标志" class="item_a">
                      <el-select    v-model="prpLDrugCata.delFlag">
                        <el-option value="" label="请选择"></el-option>
                        <el-option
                          v-for="item in ValidFlag"
                          :key="item.codeCode"
                          :label="item.codeCName"
                          :value="item.codeCode">
                        </el-option>
                      </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <div class="select-btn-group">
                        <el-button type="primary" size="medium"  @click="onSubmitYpmugl">查询</el-button>
                        <el-button type="primary" size="medium" @click="handleReset">重置</el-button>
                        <el-button type="primary" size="medium" @click="save()" >增加</el-button>
                      </div>
                    </el-col>
                  </el-row>
              </el-form>
              <el-table
                  :data="list"
                  class="table"
                  ref="multipleTable"
                  @select="selectOne"
                  header-cell-class-name="table-header"
                  style="margin: 30px 0;border: 1px solid #d6d9d8;"
                  v-loading="loading"
                  element-loading-text="Loading....."
              >
                  <el-table-column prop="drugsCode" label="药品编码" align="center"></el-table-column>
                  <el-table-column prop="drugsName" label="中文名称" align="center"></el-table-column>
                  <el-table-column prop="drugsEName" label="英文名称" align="center"></el-table-column>
                  <el-table-column prop="pinyinCode" label="拼音助记码" align="center"></el-table-column>
                  <el-table-column prop="drugsFactoryName" label="药厂名称" align="center"></el-table-column>
                  <el-table-column prop="originPlace" :formatter="PlaceTypeFormat" label="产地" align="center"></el-table-column>
                  <el-table-column prop="startDate" label="开始日期" align="center"></el-table-column>
                  <el-table-column prop="endDate" label="终止日期" align="center"></el-table-column>
                  <el-table-column prop="delFlag" :formatter="delFlagFormat" label="有效标志" align="center"></el-table-column>
                  <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        @click="handleLook(scope.$index, scope.row)">查看</el-button>
                      <el-button
                        size="mini"
                        type="text"
                        @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                      <el-button
                        size="mini"
                        type="text"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
              </el-table>
              <div class="pagination" v-if="this.list.length!==0">
                <div class="index_page">
                  <el-pagination :current-page="pagination.currentPage" :page-size="pagination.rowsNumber"
                                 :page-sizes="[10, 20, 50, 100]"
                                 :total="pagination.totalPage" background layout="prev, pager, next,sizes,total,jumper"
                                 @size-change="handleSizeChange" @current-change="queryFun">
                  </el-pagination>
                </div>
              </div>
            </div>
        </div>
    </div>
</template>
<script>
import * as api from '@/api/basicInformation'
import * as api1 from '@/api/baseDate'
export default {
    name: 'baseform',
  inject:['reload'],
    data() {
        return {
          loading: false,
          pagination: {
            currentPage: 1, // 当前页
            rowsNumber: 10, // 每页条数
            totalPage: 0 // 总条数
          },
          id:0,
          prpLDrugCata:{
            code:'',
            drugsCode:'',
            drugsName:'',
            pinyinCode:'',
            eng:'',
            drugsFactoryName:'',
            delFlag:'',
          },
          list:[],
          listUpdate:{},
            checkList: ['急诊'],
            props: { multiple: true },
            dialogFormVisible: false,
            dialogFormVisibleUpdate: false,
            tableData: [

            ],
            options: [{
                value: 1,
                label: '东南',
                children: [{
                    value: 2,
                    label: '上海',
                    children: [
                        { value: 3, label: '普陀' },
                        { value: 4, label: '黄埔' },
                        { value: 5, label: '徐汇' }
                    ]
                }, {
                    value: 7,
                    label: '江苏',
                    children: [
                        { value: 8, label: '南京' },
                        { value: 9, label: '苏州' },
                        { value: 10, label: '无锡' }
                    ]
                }, {
                    value: 12,
                    label: '浙江',
                    children: [
                        { value: 13, label: '杭州' },
                        { value: 14, label: '宁波' },
                        { value: 15, label: '嘉兴' }
                    ]
                }]
            }, {
                value: 17,
                label: '西北',
                children: [{
                    value: 18,
                    label: '陕西',
                    children: [
                        { value: 19, label: '西安' },
                        { value: 20, label: '延安' }
                    ]
                }, {
                    value: 21,
                    label: '新疆维吾尔族自治区',
                    children: [
                        { value: 22, label: '乌鲁木齐' },
                        { value: 23, label: '克拉玛依' }
                    ]
                }]
            }],
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: true,
                type: ['步步高'],
                resource: '小天才',
                desc: '',
                options: []
            },
          ValidFlag:[
            {
              codeCode:0,
              codeCName:'无效'
            },
            {
              codeCode:1,
              codeCName:'有效'
            },
          ],
          PlaceType:[
            {
              codeCode:'1',
              codeCName:'进口'
            },
            {
              codeCode:'2',
              codeCName:'国产'
            },
          ],
          PresFlag:[
            {
              codeCode:'0',
              codeCName:'非处方药'
            },
            {
              codeCode:'1',
              codeCName:'处方药'
            },
          ],
          DoseType:[],
          ChargeCate:[],
          ChargeItemLevel:[],
          item:0,
      drugCatalogDemo:{},
        };
    },
  created() {
    this.DoseType1();
    this.ChargeCate1();
    this.onSubmitYpmugl();
  },
  methods: {

    handleSizeChange(pageSize){ // 改变当前页条数事件
      this.pagination.rowsNumber=pageSize
      this.onSubmitYpmugl();
      /* let pageIndex = this.pagination.currentPage;
       this.querySettleAuditTaskList(pageIndex,pageSize);*/
    },
    queryFun(pageNum){ // 改变当前页事件
      this.pagination.currentPage=pageNum
      this.onSubmitYpmugl();
      /* let rowsNumber = this.pagination.rowsNumber;
       this.querySettleAuditTaskList(pageNum,rowsNumber);*/
    },
    // 按条件查询
      onSubmitYpmugl() {
        var data = {
          "code": this.prpLDrugCata.code,
          "drugsCode": this.prpLDrugCata.drugsCode,
          "drugsName": this.prpLDrugCata.drugsName,
          "pinyinCode": this.prpLDrugCata.pinyinCode,
          "drugsEName": this.prpLDrugCata.drugsEName,
          "drugsFactoryName": this.prpLDrugCata.drugsFactoryName,
          "delFlag": this.prpLDrugCata.delFlag,
          "pageNum":this.pagination.currentPage,
          "pageSize":this.pagination.rowsNumber,
        }
        this.loading = true;
        api.getQueryDrugList(data
        ).then(res => {
          this.loading = false;
          if(res){
            if(res.data.resultCode !== '0000'){
              this.$message.error(res.data.resultMsg);
            }else{
              this.list = res.data.list;
              this.pagination.totalPage=res.data.total;
            }
          }else{
            this.$message.error('系统异常');
          }
        })
      },
      // 重置
      handleReset(){

      },
    save(){
      this.$router.push({
        name: 'drugCatalogDemo',
        query: {
          drugCatalogDemo: JSON.stringify(this.drugCatalogDemo),
          item: JSON.stringify(0),
        }
      })
    },
    // 查看
    handleLook(index,row){
      this.drugCatalogDemo=row,
        this.$router.push({
          name: 'drugCatalogDemo',
          query: {
            drugCatalogDemo: JSON.stringify(this.drugCatalogDemo),
            item: JSON.stringify(2),
          }
        })
    },
    delFlagFormat(row, column) {
      let delFlag = row.delFlag
      if (delFlag === 0) {
        return '无效'
      } else if (delFlag === 1) {
        return '有效'
      }
    },
    PlaceTypeFormat(row, column){
      let originPlace = row.originPlace
      if (originPlace === '1') {
        return '进口'
      } else if (originPlace === '2') {
        return '国产'
      }
    },
    // 修改方法
    handleEdit(index,row){
      this.drugCatalogDemo=row,
        this.$router.push({
          name: 'drugCatalogDemo',
          query: {
            drugCatalogDemo: JSON.stringify(this.drugCatalogDemo),
            item: JSON.stringify(1),
          }
        })
    },
    // 删除
    handleDelete(index,rew) {
      var data={
        "id":rew.id,
      }
      api.getDeleteDrug(data
      ).then(res => {
        if(res.data.resultCode){
          if(res.data.resultCode !== '0000'){
            this.$message.error(res.data.resultMsg);
          }else{
            this.$message.success(res.data.resultMsg);
          }
        }
        this.reload();
      })
    },
    /*//有效标志
    ValidFlag1(){
      var data={
        "codeType": "ValidFlag"
      }
      api.MedType(data
      ).then(res => {
        // debugger
        this.ValidFlag=res.data
      })
    },*/
    //剂型
    DoseType1(){
      var data={
        "codeType": "DoseType"
      }
      api1.MedType(data
      ).then(res => {
        // debugger
        this.DoseType=res.data
      })
    },
    // 收费类别
    ChargeCate1(){
      var data={
        "codeType": "ChargeCate"
      }
      api1.MedType(data
      ).then(res => {
        // debugger
        this.ChargeCate=res.data
      })
    },
    // 收费项目等级
    ChargeItemLevel1(){
      var data={
        "codeType": "ChargeItemLevel"
      }
      api1.MedType(data
      ).then(res => {
        // debugger
        this.ChargeItemLevel=res.data
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 分页导航
    handlePageChange(val) {
        // alert(val)
        /*this.$set(this.query, 'pageIndex', val);
        this.getData();*/
      api.getQueryDrugList({
        "head":{},
        "body":{
          "start":val,
          "pageSize":this.query.pageSize,
        }
      }).then(res => {
        console.log(res)
        if (res.head.resultCode === '0000') {
          this.data=res.body;
          debugger
          this.list=this.data.list;
        }else{
          alert('信息错误')
        }
      })
    },
  }
};
</script>